Package com.funromania.server.guice

Source Code of com.funromania.server.guice.GuiceModule

package com.funromania.server.guice;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.mgt.RememberMeManager;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.session.mgt.SessionManager;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.apache.shiro.web.mgt.WebSecurityManager;
import org.apache.shiro.web.session.mgt.ServletContainerSessionManager;

import com.funromania.server.security.shiro.DatastoreRealm;
import com.funromania.server.security.shiro.ShiroMethodInterceptor;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;

public class GuiceModule extends AbstractModule {

  @Override
  protected void configure() {
    bind(Realm.class).to(DatastoreRealm.class);
    bindInterceptor(Matchers.any(),
        Matchers.annotatedWith(RequiresRoles.class),
        new ShiroMethodInterceptor());

  }

  @Provides
  @Singleton
  WebSecurityManager provideSecurityManager(Realm realm,
      SessionManager sessionManager, RememberMeManager rememberMeManager) {
    DefaultWebSecurityManager result = new DefaultWebSecurityManager(realm);
    result.setSessionManager(sessionManager);
    result.setRememberMeManager(rememberMeManager);
    return result;
  }

  @Provides
  @Singleton
  SessionManager provideSessionManager() {
    return new ServletContainerSessionManager();
  }

  @Provides
  @Singleton
  RememberMeManager provideRememberMeManager() {
    return new CookieRememberMeManager();
  }
}
TOP

Related Classes of com.funromania.server.guice.GuiceModule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.